#include "Security.h"

struct _SECURITY * Security_Create()
{
	struct _SECURITY * S;
	S = (struct _SECURITY *)malloc(sizeof(struct _SECURITY));
	Create_Words(S);
	S->Encoded = FALSE;
	S->Next = NULL;
	S->Prev = NULL;
	return S;
}

struct _SECURITY * Security_Create_Linked(struct _SECURITY * NextS,struct _SECURITY * PrevS)
{
	struct _SECURITY * S;
	S = Security_Create();
	S->Next = NextS;
	S->Prev = PrevS;
	return S;
}

void Create_Words(struct _SECURITY * S)
{
	S->Time = Word_Create();
	S->Info = Word_Create();
}

void Security_Encode(struct _SECURITY * S,struct _BUFFER * TIME,struct _BUFFER * INFO)
{
	int i,c;
	for(i = 0,c = 0;TIME->Data[c][i];i++)
	{
		Buffer_Add_Char(S->Time->D,TIME->Data[c][i],'n');
		ITT_CHUNK_CHECK(i,c);
	}
	for(i = 0,c = 0;INFO->Data[c][i];i++)
	{
		Buffer_Add_Char(S->Info->D,INFO->Data[c][i],INFO->Color[c][i]);
		ITT_CHUNK_CHECK(i,c);
	}
	S->Encoded = TRUE;
}

void Security_Encrypt(struct _SECURITY * S)
{
	Word_Encrypt(S->Info);
	Word_Encrypt(S->Time);
}

void Security_Decrypt(struct _SECURITY * S)
{
	Word_Decrypt(S->Info);
	Word_Decrypt(S->Time);
}